#-*- coding:utf-8 -*-
# @Author : yushen
# @Time : 2020-07-15 10:39
import requests
from tests.new_InteractiveShelves.shelf_conf.shelves_conf import *
from pprint import pprint

class Get_token():
    def __cookies__(self):  #获取token
        '''获取token'''
        url = shelves_host_186 + '/buorg/v1/session/login'
        header = {"Content-Type": "application/json;charset=UTF-8",
           "application":"cms"}
        payload = {"account":shelves_account_186,"password":shelves_password_186,"clientId":1,"accountType":"BRANCH_ADMIN"}
        response = requests.post(url,json=payload,headers=header)
        token = response.json()['token']
        print(token)
        return token


class InteractiveShleves(Get_token):   #交互式货架公共方法
    def __init__(self):     #定义header
        self.headers = {
            'Content-Type':'application/json;charset=UTF-8',
            'application':'cms_ry',
            'token':Get_token().__cookies__(),
        }

    def get_device_list(self):  #设备列表
        '''设备列表'''
        url = shelves_host_186 + '/application-center-manager/device/list'
        payload = {"size":10,"current":1}
        response = requests.post(url,headers=self.headers,json=payload)
        # pprint(response.json(),indent=2)
        return response.json()

    def material_listCommodityMaterial(self,size):   #素材列表
        '''素材列表'''
        url = shelves_host_186 + '/interactive-shelf-web/material/listCommodityMaterial'
        payload = {"size":size,"current":1}
        response = requests.post(url,headers=self.headers,json=payload)
        pprint(response.json(),indent=2)
        return response.json()

    def material_getMaterialDetail(self,id):   #素材详情
        '''素材详情'''
        url = shelves_host_186 + '/interactive-shelf-web/material/getMaterialDetail'
        payload = {"id":id}
        response = requests.post(url,headers=self.headers,json=payload)
        pprint(response.json(),indent=2)
        return response.json()

    def shelfCommodity_listPageCommodity(self):   #商品选择
        '''商品选择'''
        url = shelves_host_186 + '/interactive-shelf-web/shelfCommodity/listPageCommodity'
        payload = {"size":5,"current":1}
        response = requests.post(url,headers=self.headers,json=payload)
        pprint(response.json(),indent=2)
        return response.json()

    def shelfCommodity_listCommoditySpec(self):   #规格选择
        '''规格选择'''
        url = shelves_host_186 + '/interactive-shelf-web/shelfCommodity/listCommoditySpec'
        payload = {"commodityId":93,"size":5,"current":1}
        response = requests.post(url,headers=self.headers,json=payload)
        pprint(response.json(),indent=2)
        return response.json()

    def file_upload_resourceFile(self):   #视频素材上传
        '''视频素材上传'''
        url = shelves_host_186 + '/file-store-manager/file/upload/resourceFile'
        header = {
            "User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36",
            "X-Requested-With": "XMLHttpRequest"
        }
        file = {"file": open('F:\\one.png', "rb")}
        r = requests.post(url=url, headers=header, files=file)
        print(r.json()['data']['fileCode'])
        return str(r.json()['data']['fileCode'])

    def fileUploadProgress(self):   #获取素材名称
        '''获取素材名称'''
        url = shelves_host_186 + '/file-store-manager/file/upload/fileUploadProgress?fileCode=' + self.file_upload_resourceFile()
        # print(url)
        header = {
            "User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36",
            "X-Requested-With": "XMLHttpRequest"
        }
        res = requests.get(url, headers=header)
        filename = res.json()['data']['fileName']
        print(filename)
        return filename

    def saveOrUpdateGoodsCollocation(self,name):    #素材添加
        '''素材添加'''
        url = shelves_host_186 + '/interactive-shelf-web/material/saveOrUpdateMaterial'
        payload = {"resourceType":"1","commodityId":11753,"commoditySpecId":87303,"colourValue":"#ffffff","name":name,
                   "commodityName":"主商品规格测试","commoditySpec":"2","selectMaterialCollocations":[],
                   "commodityCode":"-","commodityRfid":"DSA","isShowQrcode":0,"resourceList":
                    [{"url":"http://rongyi.b0.rongyi.com/system/dev/file/628418607931457536.jpg",
                    "fileName":"0e331f13ade7870bb31e0964805e0713.jpg"}]}
        res = requests.post(url=url, headers=self.headers, json=payload)
        # pprint(res.json())
        print(res.json())

    def material_deleteMaterial(self,id):   #删除素材
        '''删除素材'''
        url = shelves_host_186 + '/interactive-shelf-web/material/deleteMaterial'
        payload = {"id":id}
        response = requests.post(url,headers=self.headers,json=payload)
        pprint(response.json(),indent=2)
        return response.json()

    def screens_listScreen(self,size,name=None):   #屏保列表
        '''屏保列表'''
        url = shelves_host_186 + '/interactive-shelf-web/screens/listScreen'
        payload = {"size":size,"current":1,"name":name}
        response = requests.post(url,headers=self.headers,json=payload)
        pprint(response.json(),indent=2)
        return response.json()

    def shelves_saveOrUpdateShelf(self,name):   #添加货架
        '''添加货架'''
        url = shelves_host_186 + '/interactive-shelf-web/shelves/saveOrUpdateShelf'
        payload = {"shelvesType":"1","themeColorType":"1","isScan":"1","machineSize":"55","showType":"1","screenShows":"1","rfidCheckTimes":2000,"minPlayTime":2,
                   "maxPlayTime":60,"closeDelayTime":2,"showQrCode":1,"screenIds":[10],"displayOn":1,"rfidOn":1,"colourValue":"#fff","name":name,
                   "qrCode":"http://www.baidu.com","url":[{"name":"1594797455_1详情.jpg","url":"http://rongyi.b0.rongyi.com/system/dev/file/600586770194628608.jpg"}],
                   "resourceType":1,"commodityShowList":[{"showNumber":1,"materialId":37,"materialName":"官帽演示2","commodityId":92,
                    "commodityName":"GO WALK EVOLUTION ULTRA","commoditySpec":"灰色","commoditySpecId":229,
                    "commoditySkuPic":"https://buorgcostest.rongyi.com/member-logo/258/11556930111810697950551046416858371149.jpg",
                     "resourceType":7,"rfids":"E2000020670902462540D9A7,29820DEF"}],
                   "materialRfidList":[{"materialId":37,"materialName":"官帽演示2","commodityId":92,"commodityName":"GO WALK EVOLUTION ULTRA","commoditySpec":"灰色",
                    "commoditySpecId":229,"commoditySkuPic":"https://buorgcostest.rongyi.com/member-logo/258/11556930111810697950551046416858371149.jpg",
                    "resourceType":7,"rfids":"E2000020670902462540D9A7,29820DEF"}],"materialBackground":"http://rongyi.b0.rongyi.com/system/dev/file/600586770194628608.jpg",
                   "fileName":"1594797455_1详情.jpg"}
        response = requests.post(url,headers=self.headers,json=payload)
        pprint(response.json(),indent=2)
        return response.json()

    def shelves_deleteShelf(self,id):   #删除货架
        '''删除货架'''
        url = shelves_host_186 + '/interactive-shelf-web/shelves/deleteShelf'
        payload = {"id":id}
        response = requests.post(url,headers=self.headers,json=payload)
        pprint(response.json(),indent=2)
        return response.json()

    def shelves_getShelfDetail(self,id):   #货架详情
        '''货架详情'''
        url = shelves_host_186 + '/interactive-shelf-web/shelves/getShelfDetail'
        payload = {"id":id}
        response = requests.post(url,headers=self.headers,json=payload)
        pprint(response.json(),indent=2)
        return response.json()

    def shelves_listShelves(self,num):   #货架列表
        '''货架列表'''
        url = shelves_host_186 + '/interactive-shelf-web/shelves/listShelves'
        payload = {"size":num,"current":1}
        response = requests.post(url,headers=self.headers,json=payload)
        # pprint(response.json(),indent=2)
        return response.json()

    def shelves_getScreenDetail(self,id):   #屏保详情
        '''屏保详情'''
        url = shelves_host_186 + '/interactive-shelf-web/screens/getScreenDetail'
        payload = {"id":str(id)}
        response = requests.post(url,headers=self.headers,json=payload)
        pprint(response.json(),indent=2)
        return response.json()

    def shelves_saveOrUpdateScreen(self,name):   #屏保添加
        '''屏保添加'''
        url = shelves_host_186 + '/interactive-shelf-web/screens/saveOrUpdateScreen'
        payload = {"name":name,"sort":23,"url":"http://rongyi.b0.rongyi.com/system/dev/file/594730289591222272.mp4","fileName":"1593401171_LVMH交互式货架屏保2.mp4","id":"23"}
        response = requests.post(url,headers=self.headers,json=payload)
        pprint(response.json(),indent=2)
        return response.json()

    def shelves_deleteScreen(self,id):   #删除屏保
        '''删除屏保'''
        url = shelves_host_186 + '/interactive-shelf-web/screens/deleteScreen'
        payload = {"id":id}
        response = requests.post(url,headers=self.headers,json=payload)
        pprint(response.json(),indent=2)
        return response.json()

    def goodsCollocation_listGoodsCollocation(self,size):   #商品搭配列表
        '''商品搭配列表'''
        url = shelves_host_186 + '/interactive-shelf-web/goodsCollocation/listGoodsCollocation'
        payload = {"size":size,"current":1}
        response = requests.post(url,headers=self.headers,json=payload)
        pprint(response.json(),indent=2)
        return response.json()

    def goodsCollocation_getGoodsCollocationDetail(self,id):   #商品搭配详情
        '''商品搭配详情'''
        url = shelves_host_186 + '/interactive-shelf-web/goodsCollocation/getGoodsCollocationDetail'
        payload = {"id":id}
        response = requests.post(url,headers=self.headers,json=payload)
        pprint(response.json(),indent=2)
        return response.json()

    def goodsCollocation_deleteGoodsCollocation(self,id):   #搭配删除
        '''搭配删除'''
        url = shelves_host_186 + '/interactive-shelf-web/goodsCollocation/deleteGoodsCollocation'
        payload = {"id":id}
        response = requests.post(url,headers=self.headers,json=payload)
        pprint(response.json(),indent=2)
        return response.json()

    def goodsCollocation_saveOrUpdateGoodsCollocation(self,name):   #搭配添加
        '''搭配添加'''
        url = shelves_host_186 + '/interactive-shelf-web/goodsCollocation/saveOrUpdateGoodsCollocation'
        payload = {"name":name,"collocationCommodityParamList":[{"commodityId":85,"commoditySpecId":200,"id":59},{"commodityId":73,"commoditySpecId":220,"id":62},
                {"commodityId":77,"commoditySpecId":179,"id":63}],"collocationResourceParamList":[{"url":"http://rongyi.b0.rongyi.com/system/dev/file/591927227260600320.jpg",
        "fileName":"1592732854_item-3-detail-1-400.jpg"},{"url":"http://rongyi.b0.rongyi.com/system/dev/file/591927263100928000.jpg",
        "fileName":"1592732862_item-3-detail-2-400.jpg"},{"url":"http://rongyi.b0.rongyi.com/system/dev/file/591927283388776448.jpg","fileName":"1592732867_item-4-350.jpg"}],
        "collocationLabelIds":[10],"id":"28"}
        response = requests.post(url,headers=self.headers,json=payload)
        pprint(response.json(),indent=2)
        return response.json()

    def globalConfig_getGlobalConfigDetail(self):   #全局配置详情
        '''全局配置详情'''
        url = shelves_host_186 + '/interactive-shelf-web/globalConfig/getGlobalConfigDetail'
        payload = {}
        response = requests.post(url,headers=self.headers,json=payload)
        pprint(response.json(),indent=2)
        return response.json()

    def globalConfig_saveOrUpdateGlobalConfig(self):   #修改全局配置
        '''修改全局配置'''
        url = shelves_host_186 + '/interactive-shelf-web/globalConfig/saveOrUpdateGlobalConfig'
        payload = {"color":"#dd69f4"}
        response = requests.post(url,headers=self.headers,json=payload)
        pprint(response.json(),indent=2)
        return response.json()

    def collocationLabel_list(self,size):   #搭配标签列表
        '''搭配标签列表'''
        url = shelves_host_186 + '/interactive-shelf-web/collocationLabel/list'
        payload = {"size":size,"current":1}
        response = requests.post(url,headers=self.headers,json=payload)
        # pprint(response.json(),indent=2)
        return response.json()

    def collocationLabel_info(self,id):   #搭配标签详情
        '''搭配标签详情'''
        url = shelves_host_186 + '/interactive-shelf-web/collocationLabel/info'
        payload = {"id":id}
        response = requests.post(url,headers=self.headers,json=payload)
        pprint(response.json(),indent=2)
        return response.json()

    def collocationLabel_edit(self,name,nglishName,sort):   #标签添加
        '''
        标签添加
        :param name: 标签名
        :param nglishName: 英文名
        :param sort: 展示权重
        :return:
        '''
        url = shelves_host_186 + '/interactive-shelf-web/collocationLabel/edit'
        payload = {"name":name,"englishName":nglishName,"sort":sort,"backUrl":"http://rongyi.b0.rongyi.com/system/dev/file/600602104846876672.jpg","backUrlName":"1594801111_1.jpg"}
        response = requests.post(url,headers=self.headers,json=payload)
        pprint(response.json(),indent=2)
        return response.json()

    def collocationLabel_delete(self,id):   #搭配标签删除
        '''搭配标签详情'''
        url = shelves_host_186 + '/interactive-shelf-web/collocationLabel/delete'
        payload = {"id":id}
        response = requests.post(url,headers=self.headers,json=payload)
        pprint(response.json(),indent=2)
        return response.json()


    # def collocationLabel_delete(self,id):   #搭配标签详情
    #     '''搭配标签详情'''
    #     url = shelves_host_186 + '/interactive-shelf-web/collocationLabel/delete'
    #     payload = {"id":id}
    #     response = requests.post(url,headers=self.headers,json=payload)
    #     pprint(response.json(),indent=2)
    #     return response.json()
if __name__ == '__main__':
    cm = Get_token()
    cm.shelves_getShelfDetail()